package mapred.task.example;

import java.io.IOException;
import java.util.Iterator;

import mapred.task.AbstractReducer;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

public class DoubleSumReducer extends AbstractReducer<Writable, DoubleWritable, Writable, DoubleWritable> {

    @Override
    public void reduce(Writable key, Iterator<DoubleWritable> values,
            OutputCollector<Writable, DoubleWritable> output, Reporter reporter)
            throws IOException {
        double sum = 0;
        while (values.hasNext()) {
            sum += values.next().get();
        }
        output.collect(key, new DoubleWritable(sum));
    }

    @Override
    protected void setUp() {
    }

}
